package com.manager.controller;

import com.manager.bean.StudentAccess;
import com.manager.bean.view.StudentAccessView;
import com.manager.service.StudentAccessService;
import com.manager.service.view.StudentAccessViewService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

import com.manager.bean.PageInfo;

/**
 * (StudentAccess)表控制层
 *
 * @author makejava
 * @since 2021-03-02 20:15:30
 */
@Controller
public class StudentAccessController {
    /**
     * 服务对象
     */
    @Resource
    private StudentAccessService StudentAccessService;

    @Resource
    private StudentAccessViewService studentAccessViewService;

    @RequestMapping(value = "/findStudentAccess")
    public String findStudentAccess(Model model,Integer Id, String Name, Integer pageIndex, Integer pageSize) {
        PageInfo<StudentAccessView> pi =  studentAccessViewService.findPageInfo(Id,Name,pageIndex,pageSize);
        model.addAttribute("pi", pi);
        return "StudentAccess_list";
    }


    @RequestMapping(value = "/exportStudentAccesslist", method = RequestMethod.POST)
    @ResponseBody
    public List<StudentAccessView> exportStudentAccess() {
        List<StudentAccessView> StudentAccessList = studentAccessViewService.getAll();
        return StudentAccessList;
    }


    @RequestMapping("/deleteStudentAccess")
    @ResponseBody
    public String deleteStudentAccess(Integer Id) {
        StudentAccessService.deleteById(Id);
        return "StudentAccess_list";
    }


    @RequestMapping(value = "/addStudentAccess", method = RequestMethod.POST)
    @ResponseBody
    public String addStudentAccess(@RequestBody StudentAccess StudentAccess) {
        StudentAccessService.insert(StudentAccess);
        return "StudentAccess_list";
    }


    @RequestMapping(value = "/updateStudentAccess", method = RequestMethod.POST)
    public String updateStudentAccess(StudentAccess StudentAccess) {
        StudentAccessService.update(StudentAccess);
        return "redirect:/findStudentAccess";
    }


    @RequestMapping("/findStudentAccessById")
    public String findStudentAccessById(Integer Id, HttpSession session, Model model) {
        StudentAccess s = StudentAccessService.queryById(Id);
        session.setAttribute("s", s);
        model.addAttribute("s", s);
        return "StudentAccess_edit";
    }

}
